home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / REALDOS.C < prev    next >
C/C++ Source or Header  |  1993-08-24  |  53KB  |  1,775 lines

  1. /*
  2.     Miscellaneous C routines used only in DOS Fractint.
  3. */
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7. #ifndef XFRACT
  8. #include <dos.h>
  9. #include <io.h>
  10. #include <process.h>
  11. #endif
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #include <fcntl.h>
  15. #include <math.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18. #include "fractint.h"
  19. #include "fractype.h"
  20. #include "helpdefs.h"
  21. #include "prototyp.h"
  22.  
  23. /* routines in this module    */
  24.  
  25. static int menu_checkkey(int curkey,int choice);
  26.  
  27. /* uncomment following for book version */
  28. /* #define WAITE */
  29.  
  30. int release=1820; /* this has 2 implied decimals; increment it every synch */
  31. int patchlevel=0; /* patchlevel for DOS version */
  32. int xrelease=202;
  33.  
  34. /* fullscreen_choice options */
  35. #define CHOICERETURNKEY 1
  36. #define CHOICEMENU    2
  37. #define CHOICEHELP    4
  38.  
  39. extern char diskfilename[];
  40. extern int using_jiim;
  41. extern int  xdots, ydots, sxdots, sydots, sxoffs, syoffs, vxdots;
  42. extern int  colors;
  43. extern int  dotmode;
  44. extern int  oktoprint;
  45. extern int  textrow, textcol, textrbase, textcbase;
  46. extern int  debugflag;
  47. extern int  fractype;
  48. extern int  calc_status;
  49. extern double param[];
  50. extern int  tabmode;
  51. extern int  color_dark,color_medium,color_bright;
  52. extern int  lookatmouse;
  53. extern int  gotrealdac;
  54. extern int  reallyega;
  55. extern SEGTYPE  extraseg;
  56. extern int  active_system;
  57. extern int  first_init;
  58. extern int initbatch;        /* 1 if batch run (no kbd)  */
  59.  
  60.  
  61. /* int stopmsg(flags,message) displays message and waits for a key:
  62.      message should be a max of 9 lines with \n's separating them;
  63.        no leading or trailing \n's in message;
  64.        no line longer than 76 chars for best appearance;
  65.      flag options:
  66.        &1 if already in text display mode, stackscreen is not called
  67.       and message is displayed at (12,0) instead of (4,0)
  68.        &2 if continue/cancel indication is to be returned;
  69.       when not set, "Any key to continue..." is displayed
  70.       when set, "Escape to cancel, any other key to continue..."
  71.       -1 is returned for cancel, 0 for continue
  72.        &4 set to suppress buzzer
  73.        &8 for Fractint for Windows & parser - use a fixed pitch font
  74.       &16 for info only message (green box instead of red in DOS vsn)
  75.    */
  76. int stopmsg (int flags, CHAR far *msg)
  77. {
  78.    int ret,toprow,color,savelookatmouse;
  79.    if (active_system == 0 /* DOS */
  80.      && first_init) {      /* & cmdfiles hasn't finished 1st try */
  81.       setvideotext();
  82.       buzzer(2);
  83.       putstring(0,0,15,"*** Error during startup:");
  84.       putstring(2,0,15,msg);
  85.       movecursor(8,0);
  86. #ifdef XFRACT
  87.       sleep(1);
  88.       UnixDone();
  89. #endif
  90.       exit(1);
  91.       }
  92.    if (initbatch == 1) { /* in batch mode */
  93.       initbatch = 4; /* used to set errorlevel */
  94.       return (-1);
  95.       }
  96.    ret = 0;
  97.    savelookatmouse = lookatmouse;
  98.    lookatmouse = -13;
  99.    if ((flags & 1))
  100.       blankrows(toprow=12,10,7);
  101.    else {
  102.       stackscreen();
  103.       toprow = 4;
  104.       movecursor(4,0);
  105.       }
  106.    textcbase = 2; /* left margin is 2 */
  107.    putstring(toprow,0,7,msg);
  108.    if (flags & 2)
  109.       putstring(textrow+2,0,7,"Escape to cancel, any other key to continue...");
  110.    else
  111.       putstring(textrow+2,0,7,"Any key to continue...");
  112.    textcbase = 0; /* back to full line */
  113.    color = (flags & 16) ? C_STOP_INFO : C_STOP_ERR;
  114.    setattr(toprow,0,color,(textrow+1-toprow)*80);
  115.    movecursor(25,80);    /* cursor off */
  116.    if ((flags & 4) == 0)
  117.       buzzer((flags & 16) ? 0 : 2);
  118.    while (keypressed()) /* flush any keyahead */
  119.       getakey();
  120.    if (getakeynohelp() == ESC)
  121.       ret = -1;
  122.    if ((flags & 1))
  123.       blankrows(toprow,10,7);
  124.    else
  125.       unstackscreen();
  126.    lookatmouse = savelookatmouse;
  127.    return ret;
  128. }
  129.  
  130.  
  131. static char far *temptextsave = NULL;
  132. static int  textxdots,textydots;
  133.  
  134. /* texttempmsg(msg) displays a text message of up to 40 characters, waits
  135.       for a key press, restores the prior display, and returns (without
  136.       eating the key).
  137.       It works in almost any video mode - does nothing in some very odd cases
  138.       (HCGA hi-res with old bios), or when there isn't 10k of temp mem free. */
  139. int texttempmsg(char *msgparm)
  140. {
  141.    if (showtempmsg(msgparm))
  142.       return(-1);
  143. #ifndef XFRACT
  144.    while (!keypressed()) {} /* wait for a keystroke but don't eat it */
  145. #else
  146.    waitkeypressed(0); /* wait for a keystroke but don't eat it */
  147. #endif
  148.    cleartempmsg();
  149.    return(0);
  150. }
  151.  
  152. void freetempmsg()
  153. {
  154.    if(temptextsave != NULL)
  155.       farmemfree(temptextsave);
  156.    temptextsave = NULL;
  157. }
  158.  
  159. int showtempmsg(char *msgparm)
  160. {
  161.    static long size = 0;
  162.    extern int color_dark,color_medium;
  163.    CHAR msg[41];
  164.    BYTE buffer[640];
  165.    char far *fartmp;
  166.    BYTE far *fontptr;
  167.    BYTE *bufptr;
  168.    int i,j,k,xrepeat,yrepeat,fontchar,charnum;
  169.    int save_sxoffs,save_syoffs;
  170.    strncpy(msg,msgparm,40);
  171.    msg[40] = 0; /* ensure max message len of 40 chars */
  172.    if (dotmode == 11) { /* disk video, screen in text mode, easy */
  173.       dvid_status(0,msg);
  174.       return(0);
  175.       }
  176.    if ((fontptr = findfont(0)) == NULL) { /* old bios, no font table? */
  177.       if (oktoprint == 0           /* can't printf */
  178.     || sxdots > 640 || sydots > 200) /* not willing to trust char cell size */
  179.      return(-1); /* sorry, message not displayed */
  180.       textydots = 8;
  181.       textxdots = sxdots;
  182.       }
  183.    else {
  184.       xrepeat = (sxdots >= 640) ? 2 : 1;
  185.       yrepeat = (sydots >= 300) ? 2 : 1;
  186.       textxdots = strlen(msg) * xrepeat * 8;
  187.       textydots = yrepeat * 8;
  188.       }
  189.    /* worst case needs 10k */
  190.    if(temptextsave !=NULL)
  191.       if(size != (long)textxdots * (long)textydots)
  192.          freetempmsg();      
  193.    size = (long)textxdots * (long)textydots;
  194.    save_sxoffs = sxoffs;
  195.    save_syoffs = syoffs;
  196.    sxoffs = syoffs = 0;
  197.    if(temptextsave == NULL) /* only save screen first time called */
  198.    {
  199.       if ((temptextsave = farmemalloc(size)) == NULL)
  200.          return(-1); /* sorry, message not displayed */
  201.       fartmp = temptextsave;
  202.       for (i = 0; i < textydots; ++i) {
  203.          get_line(i,0,textxdots-1,buffer);
  204.          for (j = 0; j < textxdots; ++j) /* copy it out to far memory */
  205.          *(fartmp++) = buffer[j];
  206.          }
  207.       }
  208.    if (fontptr == NULL) { /* bios must do it for us */
  209.       home();
  210.       printf(msg);
  211.       }
  212.    else { /* generate the characters */
  213.       find_special_colors(); /* get color_dark & color_medium set */
  214.       for (i = 0; i < 8; ++i) {
  215.      memset(buffer,color_dark,640);
  216.      bufptr = buffer;
  217.      charnum = -1;
  218.      while (msg[++charnum] != 0) {
  219.         fontchar = *(fontptr + msg[charnum]*8 + i);
  220.         for (j = 0; j < 8; ++j) {
  221.            for (k = 0; k < xrepeat; ++k) {
  222.           if ((fontchar & 0x80) != 0)
  223.              *bufptr = color_medium;
  224.           ++bufptr;
  225.           }
  226.            fontchar <<= 1;
  227.            }
  228.         }
  229.      for (j = 0; j < yrepeat; ++j)
  230.         put_line(i*yrepeat+j,0,textxdots-1,buffer);
  231.      }
  232.       }
  233.    sxoffs = save_sxoffs;
  234.    syoffs = save_syoffs;
  235.    return(0);
  236. }
  237.  
  238. void cleartempmsg()
  239. {
  240.    BYTE buffer[640];
  241.    char far *fartmp;
  242.    int i,j;
  243.    int save_sxoffs,save_syoffs;
  244.    if (dotmode == 11) /* disk video, easy */
  245.       dvid_status(0,"");
  246.    else if (temptextsave != NULL) {
  247.       save_sxoffs = sxoffs;
  248.       save_syoffs = syoffs;
  249.       sxoffs = syoffs = 0;
  250.       fartmp = temptextsave;
  251.       for (i = 0; i < textydots; ++i) {
  252.      for (j = 0; j < textxdots; ++j) /* copy back from far memory */
  253.         buffer[j] = *(fartmp++);
  254.      put_line(i,0,textxdots-1,buffer);
  255.      }
  256.      if(using_jiim == 0)  /* jiim frees memory with freetempmsg() */
  257.      {
  258.          farmemfree(temptextsave);
  259.          temptextsave = NULL;
  260.       }
  261.       sxoffs = save_sxoffs;
  262.       syoffs = save_syoffs;
  263.       }
  264. }
  265.  
  266.  
  267. void blankrows(int row,int rows,int attr)
  268. {
  269.    char buf[81];
  270.    memset(buf,' ',80);
  271.    buf[80] = 0;
  272.    while (--rows >= 0)
  273.       putstring(row++,0,attr,buf);
  274.    }
  275.  
  276.  
  277. void helptitle()
  278. {
  279.    char msg[80],buf[80];
  280.    setclear(); /* clear the screen */
  281. #ifdef XFRACT
  282.    sprintf(msg,"XFRACTINT  Version %d.%02d (FRACTINT Version %d.%02d)",
  283.            xrelease/100,xrelease%100, release/100,release%100);
  284.    putstringcen